home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 16 / AMIGAplus Sonderheft 16 (1998)(ICP)(DE)[!].iso / pd / anwendungen / ispell-3.1.18bin / interfaces / guispell-1.1 / error.c < prev    next >
C/C++ Source or Header  |  1995-09-21  |  1KB  |  73 lines

  1. #include <stdlib.h>
  2. #include <stdarg.h>
  3. #include <string.h>
  4. #pragma msg 148 ignore push
  5. #pragma msg 149 ignore push
  6. #pragma msg 61 ignore push
  7. #include <proto/exec.h>
  8. #include <proto/dos.h>
  9. #pragma msg 149 pop
  10. #pragma msg 61 pop
  11. #include "error.h"
  12.  
  13. static void (*CleanupCode)(void);
  14.  
  15. static void PrintMessage (char **code)
  16. {
  17.   struct DosLibrary *DOSBase = (struct DosLibrary *) OpenLibrary (DOSNAME, 0);
  18.  
  19.   if (DOSBase)
  20.     {
  21.       if (Output ())
  22.         {
  23.       va_list ap;
  24.       char *string;
  25.       int number;
  26.       char buffer[(sizeof (int)) * 4];
  27.       int i;
  28.  
  29.       va_start (ap, *code);
  30.       while (**code)
  31.             switch (**code)
  32.           {
  33.           case 'd':
  34.             number = va_arg (ap, int);
  35.             buffer[15] = '\0';
  36.             buffer[14] = '0';
  37.             for (i = 14; number; i--)
  38.               buffer[i] = number % 10 + '0', number /= 10;
  39.             string = &buffer[++i];
  40.             goto write_error;
  41.           case 's':
  42.             string = va_arg (ap, char *);
  43.           write_error:
  44.                 Write (Output (), string, strlen (string));
  45.             (*code)++;
  46.             break;
  47.           default:
  48.             **code = '\0';
  49.           }
  50.           va_end (ap);
  51.         }
  52.       CloseLibrary ((struct Library *) DOSBase);
  53.     }
  54. }
  55.  
  56. void Warning (char *code, ...)
  57. {
  58.   PrintMessage (&code);
  59. }
  60.  
  61. void Error (char *code, ...)
  62. {
  63.   PrintMessage (&code);
  64.   if (CleanupCode)
  65.     (*CleanupCode) ();
  66.   exit (EXIT_FAILURE);
  67. }
  68.  
  69. void OnError (void (*f)(void))
  70. {
  71.   CleanupCode = f;
  72. }
  73.